package com.pyf.sportsheadline.activities;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.pyf.sportsheadline.R;
import com.pyf.sportsheadline.fragments.EventFragment;
import com.pyf.sportsheadline.fragments.HeadlineFragment;
import com.pyf.sportsheadline.fragments.NewsFragment;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

    private RadioGroup main_rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        getSupportFragmentManager().beginTransaction().add(R.id.main_container, new NewsFragment()).commit();
        main_rg = (RadioGroup) findViewById(R.id.main_radioGroup);
        main_rg.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        switch (i) {
            case R.id.main_rb_news:
                transaction.replace(R.id.main_container, new NewsFragment());
                break;
            case R.id.main_rb_headline:
                transaction.replace(R.id.main_container, new HeadlineFragment());
                break;
            case R.id.main_rb_event:
                transaction.replace(R.id.main_container, new EventFragment());
                break;
        }
        transaction.commit();
    }
}
